#pragma
#include <iostream>
#include <string>
#include <functional>
#include <cstdio>

//typedef std::function<void*(void*)> fun_t;
//using fun_t= std::function<void*(void*)>;
typedef void*(*fun_t)(void*);

class ThreadData
{
public:
    void *args_;
    std::string name_;
    //...可以是类外部传进来的，也可以是Thread类内部构造时候赋值的
};

class Thread
{
public:
    Thread(int num,fun_t callback,void* args):func_(callback)//构造线程
    {
        char nameBuffer[64];
        snprintf(nameBuffer,sizeof nameBuffer,"Thread-%d",num);
        name_=nameBuffer;
        tdata_.args=args;
        tdata_.name_=name_;
    }

    void Start()
    {
        pthread_create(&tid_,nullptr,func_,(void*)&tdata_);
    }
    
    void join()
    {
        pthread_join(tid_,nullptr);
    }

    std::string name()
    {
        return name_;
    }

    ~Thread()
    {}
private:
    std::string name_;
    fun_t func_;//线程例程函数
    ThreadData tdata_;
    pthread_t tid_;
};